﻿using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Windows.Forms;
using BackupRestoreSoftwares.FormChild;

namespace BackupRestoreSoftwares
{
    public partial class frmMain : Form
    {
        private bool isDown; //cờ báo chuột có được nhấn hay không
        private int xDown, yDown; //lưu vị trí được nhấn của chuột

        public frmMain()
        {
            InitializeComponent();
        }

        public static void waitscreen()
        {
            Application.Run(new frmwait());
        }

        private void btn_backup_Click(object sender, EventArgs e)
        {
            pn_main.Controls.Clear();
            var frm = new m_Backup();
            frm.Dock = DockStyle.Fill;
            pn_main.Controls.Add(frm);
        }

        private void btn_restore_Click(object sender, EventArgs e)
        {
            pn_main.Controls.Clear();
            var frm = new m_Restore();
            frm.Dock = DockStyle.Fill;
            pn_main.Controls.Add(frm);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void pn_title_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //đổi cờ báo
                isDown = true;
                //lưu lại vị trí nhấn
                xDown = e.X;
                yDown = e.Y;
            }
        }

        private void pn_title_MouseMove(object sender, MouseEventArgs e)
        {
            if (isDown)
            {
                //thay đổi vị trí Form
                Left += (e.X - xDown);
                Top += (e.Y - yDown);
            }
        }

        private void pn_title_MouseUp(object sender, MouseEventArgs e)
        {
            //đổi cờ báo
            isDown = false;
        }

        private void label2_Click(object sender, EventArgs e)
        {
            Process.Start("http://softpc86vn.blogspot.com");
        }

        private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        #region Bar Button

        private void Form1_Load(object sender, EventArgs e)
        {
            lbl_ver_main.Text = "Version: " + ProductVersion;
            if (File.Exists("Rar.exe") != true)
            {
                var webClient = new WebClient();
                webClient.DownloadFileAsync(new Uri(frmCheck.GetLinkMain + frmCheck.GetRarFiles),
                    Application.StartupPath + @"\Rar.exe");
            }
            // https://softpc86vn.googlecode.com/svn/update/Backup-Restore/update-info.xml 
            //btn_backup_Click(sender, e);
            Lock();
            btn_backup.Enabled = false;
            btn_restore.Enabled = false;
        }

        private void btn_Tool_Click(object sender, EventArgs e)
        {
            pn_main.Controls.Clear();
            var frm = new m_Main();
            frm.Dock = DockStyle.Fill;
            pn_main.Controls.Add(frm);
        }

        private void btn_About_Click(object sender, EventArgs e)
        {
            pn_main.Controls.Clear();
            var frm = new m_About();
            frm.Dock = DockStyle.Fill;
            pn_main.Controls.Add(frm);
        }

        private void btn_unlock_Click(object sender, EventArgs e)
        {
            btn_backup.Enabled = true;
            btn_restore.Enabled = true;
        }

        private void Lock()
        {
            pn_main.Controls.Clear();
            var frm = new m_Splash();
            frm.Dock = DockStyle.Fill;
            pn_main.Controls.Add(frm);
        }

        #endregion
    }
}